﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CharacterAnimationManager : MonoBehaviour {

	public Animator _animator;
	public string[] Animations;

	public string defaultAnimation;
	public string currentAnimation;
	
	public void SetAnimation(string anim)
	{
		foreach(string s in Animations)
		{
			if(s.Equals(anim))
				currentAnimation = anim;
			print(s.Equals(anim));
			_animator.SetBool(s, s.Equals(anim));

			print (anim);
		}
	}

	public void SetDefault()
	{
		foreach(string s in Animations)
		{
			_animator.SetBool(s, false);
		}
	}

	// Use this for initialization
	void Start () {
		Dialoguer.Initialize ();
		Dialoguer.events.onMessageEvent += HandleonMessageEvent;
	}

	void HandleonMessageEvent (string message, string metadata)
	{
		switch(message)
		{
			case "SetAnimation":
			SetAnimation(metadata);
			break;
			default:
			return;
			break;
		}

		//gameObject.SendMessage (message, metadata);
	}

	void Update()
	{
		bool foundAnim = false;
		for (int i = 0; i < Animations.Length; i++) {
		
			if(Animations[i] == currentAnimation)
			{
				SetAnimation(currentAnimation);
				foundAnim = true;
			}
		}

		if (!foundAnim)
			SetDefault ();

		print (foundAnim);
	}
}